package ua.mykola.graph;

public class DFS extends FirstSearch {

	public DFS(Graph graph, String vertexLabel) {
		super(graph, vertexLabel);
	}

	public DFS(Graph graph, Vertex vertex) {
		super(graph, vertex);
	}

	@Override
	protected void traverse(Vertex vertex) {
		visited.add(vertex);
		for (Edge edge : graph.getEdgesFrom(vertex)) {
			Vertex otherSide = edge.getOtherSide(vertex);
			if (!visited.contains(otherSide)) {
				pathUp.put(otherSide, edge);
				traverse(otherSide);
			}
		}
	}

}
